/*
Abstract:
  Main structures definitions

Last changed:
  $Id: structures.h 55 2009-03-26 10:54:52Z vitamin.caig $

Author:
  (C) Vitamin/CAIG/2001

  This file is the part of Textator project
*/
#ifndef __STRUCTURES_H_DEFINED__
#define __STRUCTURES_H_DEFINED__

#include "types.h"

#include <vector>

//describes one token
struct Token
{
  enum TokenType
  {
    TEXT,
    VARIABLE
  };
  Token() : Type(TEXT)
  {
  }
  Token(TokenType type, const String& value) : Type(type), Value(value)
  {
  }
  TokenType Type;
  String Value;
};

//set of tokens
typedef std::vector<Token> TokensList;

//describes one entry
struct Entry
{
  enum EntryType
  {
    LOCAL,
    GLOBAL
  };
  Entry() : Type(LOCAL)
  {
  }
  explicit Entry(EntryType type) : Type(type)
  {
  }
  Entry(EntryType type, Token::TokenType tktype, const String& tkvalue) : Type(type), Value(1, Token(tktype, tkvalue))
  {
  }
  EntryType Type;
  TokensList Value;
};

//describes full tokenized map
typedef std::map<String, Entry> EntriesMap;

const String::value_type HEADER_NAME[] = {'_', '_', 'H', 'E', 'A', 'D', 'E', 'R', '_', '_', '\0'};
const String::value_type FOOTER_NAME[] = {'_', '_', 'F', 'O', 'O', 'T', 'E', 'R', '_', '_', '\0'};
const String::value_type RAW_HEADER_NAME[] = {'_', '_', 'R', 'A', 'W', 'H', 'E', 'A', 'D', 'E', 'R', '_', '_', '\0'};
const String::value_type RAW_FOOTER_NAME[] = {'_', '_', 'R', 'A', 'W', 'F', 'O', 'O', 'T', 'E', 'R', '_', '_', '\0'};

inline bool IsSpecialToken(const String& name)
{
  return name == HEADER_NAME || name == FOOTER_NAME || name == RAW_HEADER_NAME || name == RAW_FOOTER_NAME;
}

/* data streams structure

InStream -> [ Parser(key) ] -> TokensMap
TokensMap -> [ Complex*Unparser ] -> OutStream
TokensMap -> [ Synthesizer ] -> StringMap
StringMap -> [ Simple*Unparser ] -> OutStream
StringMap -> [ Analyzer ] -> TokensMap

*/
#endif //__STRUCTURES_H_DEFINED__
